package edu.hrbeu.crc.constant;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Objects;

public class ErrorConstant {

    public static final String LOGIN_ERROR = "用户名或密码错误";

    public static final String NAME_NULL_OR_PASSWORD_NULL = "用户名或密码为空";

    public static final String USERNAME_REPETITION = "用户名重复";

    public static final String PASSWORD_VIOLATION = "密码不符合规范";

    public static final String FILE_TYPE_STANDARDIZED = "仅支持上传.xlsx格式的Excel文件";

    public static final String SHEET2_NOT_EXIST = "请将账单明细放入sheet2";

    public static final String TABLE_HEADER_NOT_EXIST = "表头行不存在，请检查文件格式";

    public static final String MISSING_TABLE_HEADER = "表头缺失：";

    public static final String FILE_READING_FAILED = "文件读取失败，请检查文件是否损坏";

    public static final String FAILED_EXPORT_BILL = "账单导出失败";

    public static final String FILE_BE_EMPTY = "上传文件不能为空";

    public static final String OSS_SERVICE_EXCEPTION = "OSS服务异常：";

    public static final String CLIENT_CONNECTION_EXCEPTION = "客户端连接异常：";

    public static final String CURRENT_GE_TARGET = "当前存的钱都大于目标金额了啊喂！";



    public static boolean isValidErrorMsg(String msg) {
        // 获取类的所有字段
        Field[] fields = ErrorConstant.class.getDeclaredFields();
        for (Field field : fields) {
            // 筛选
            if (Modifier.isStatic(field.getModifiers())
                    && field.getType() == String.class) {
                try {
                    // 获取静态字段的值
                    String constantValue = (String) field.get(null);
                    // 比较值
                    if (Objects.equals(msg, constantValue)) {
                        return true;
                    }
                } catch (IllegalAccessException e) {
                    // 反射访问异常时，抛出运行时异常提示
                    throw new RuntimeException("未知错误", e);
                }
            }
        }
        return false;
    }
}
